<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrderTable extends Migration {
	public function up() {
		//订单
		Schema::create( 'recharge', function ( Blueprint $table ) {
			$table->increments( 'id' );
			$table->unsignedInteger( 'user_id' )->comment( '用户ID' );
			$table->string( 'out_trade_no', 23 )->comment( '订单号' );
			$table->string( 'subject' )->comment( '标题' );
			$table->unsignedDecimal( 'recharge_amount', 10, 2 )->comment( '充值金额' );
			$table->unsignedDecimal( 'total_amount', 10, 2 )->default( 0 )->comment( '实收金额' );
			$table->boolean( 'pay_status' )->default( false )->comment( '支付状态 未支付:0 已支付:1' );
			$table->boolean( 'refund_status' )->default( false )->comment( '退款状态 未退款:0 退款:1' );
			$table->boolean( 'deleted' )->default( false )->comment( '管理员删除 0=未删除,1=删除' );
			$table->timestamps();
		} );
		//快照
		Schema::create( 'recharge_order_snapshot', function ( Blueprint $table ) {
			$table->increments( 'id' );
			$table->unsignedInteger( 'user_id' )->comment( '用户ID' );
			$table->string( 'out_trade_no', 23 )->comment( '订单号' );
			$table->unsignedDecimal( 'total_price', 10, 2 )->comment( '订单金额' );
			$table->timestamps();
		} );
		//支付日志
		Schema::create( 'pay_log', function ( Blueprint $table ) {
			$table->increments( 'id' );
			$table->unsignedInteger( 'user_id' )->comment( '用户ID' );
			$table->string( 'out_trade_no', 23 )->comment( '订单号' );
			$table->unsignedTinyInteger( 'pay_type' )->comment( '支付类型 管理员充值:0 支付宝:1 微信:2' );
			$table->unsignedDecimal( 'total_amount', 10, 2 )->default( 0 )->comment( '实收金额' );
			$table->timestamps();
		} );
		// cash日志
		Schema::create( 'cash_log', function ( Blueprint $table ) {
			$table->bigIncrements( 'id' );
			$table->unsignedBigInteger( 'user_id' )->comment( '用户ID' );
			$table->string( 'out_trade_no', 23 )->comment( '订单号' );
			$table->string( 'operator', 50 )->comment( '操作人' );
			$table->decimal( 'value', 10, 2 )->comment( '涉及金额' );
			$table->decimal( 'before', 10, 2 )->comment( '之前' );
			$table->decimal( 'after', 10, 2 )->comment( '之后' );
			$table->tinyInteger( 'type' )->comment( '操作类型 管理员扣除:-1 管理员充值:0 支付宝充值:1 微信充值:2  消费:11 退款:12 申请提现:13 提现驳回:14 奖励:21 转入:41 转出:42' );
			$table->string( 'remarks' )->comment( '备注' );
			$table->timestamps();
		} );
		//退款日志
		Schema::create( 'refund_log', function ( Blueprint $table ) {
			$table->increments( 'id' );
			$table->unsignedInteger( 'user_id' )->comment( '用户ID' );
			$table->string( 'out_trade_no', 23 )->comment( '订单号' );
			$table->string( 'trade_no', 64 )->comment( '第三方交易号' );
			$table->string( 'buyer_id', 64 )->comment( '第三方用户ID' );
			$table->unsignedTinyInteger( 'type' )->comment( '退款类型 支付宝:1 微信:2' );
			$table->decimal( 'total_amount', 10, 2 )->comment( '退款金额' );
			$table->timestamp( 'refund_time' )->comment( '退款时间' );
			$table->timestamps();
		} );
	}

	public function down() {
		Schema::dropIfExists( 'order' );
		Schema::dropIfExists( 'order_snapshot' );
		Schema::dropIfExists( 'pay_log' );
		Schema::dropIfExists( 'cash_log' );
		Schema::dropIfExists( 'refund_log' );
	}
}
